﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Configuration;
using BHair.bb;
using DevExpress.XtraReports.UI;

namespace BHair.Report
{
    public partial class frmsrmx : WeifenLuo.WinFormsUI.Docking.DockContent
    {
        public frmsrmx()
        {
            InitializeComponent();
        }
        string constr = ConfigurationManager.ConnectionStrings["BHair.Properties.Settings.BHairDBConnectionString"].ConnectionString;
        private void button1_Click(object sender, EventArgs e)
        {
            selectall();
        }
        public DataSet selectall()
        {
            string xx = "";
            if (comboBox1.Text == "办卡")
            {
                xx = "BK";
            }
            else if (comboBox1.Text == "预存项目")
            {
                xx = "YC";
            }
            else if (comboBox1.Text == "卡续期")
            {
                xx = "XQ";
            }
            else if (comboBox1.Text == "项目充次")
            {
                xx = "CC";
            }
            else if (comboBox1.Text == "会员储值")
            {
                xx = "CZ";
            }
            else
            {
                xx = "";
            }
                
    



            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            SqlConnection conn = new SqlConnection(constr);
            string sql =string.Format( "SELECT [djh] as 单号"
                + "      ,[skje] as 收款金额"
                + "      ,[zsje] as 赠送金额"
                + "      ,[yhje] as 优惠金额"
                + "      ,积分抵扣 as 积分抵扣"
                + "      ,[djje] as 单据金额"
                + "      ,[skfs] as 收款方式"
                + "      ,[djbz] as 单据备注"
                + "      ,[jsr]  as 经手人"
                + "      ,[djrq] as 单据日期"
                + "  FROM [BHairDB].[dbo].[收入明细]"
                + "  where '{0}'<=djrq and '{1}'>=djrq and djh like '%{2}%'",dtpbegin.Text,dtpend.Text,xx);
            conn.Open();
            SqlDataAdapter sda = new SqlDataAdapter(sql,conn);
            sda.Fill(dt);
            this.dataGridView1.DataSource = dt;
            SqlConnection conn1 = new SqlConnection(constr);
            conn1.Open();
            string sql1 =string.Format("SELECT COUNT(*)FROM [BHairDB].[dbo].[收入明细] where '{0}'<=djrq and '{1}'>=djrq and djh like '%{2}%' ", dtpbegin.Text, dtpend.Text,xx);
            SqlCommand comm1 = new SqlCommand(sql1,conn1);
            int djs=Int32.Parse(comm1.ExecuteScalar().ToString());
            lbdjs.Text = djs.ToString();
            string sql2 =string.Format("SELECT SUM(skje) FROM [BHairDB].[dbo].[收入明细] where '{0}'<=djrq and '{1}'>=djrq and djh like '%{2}%' ", dtpbegin.Text, dtpend.Text,xx);
            SqlConnection conn2 = new SqlConnection(constr);
            conn2.Open();
            SqlCommand comm2 = new SqlCommand(sql2,conn2);
            lbskje.Text = comm2.ExecuteScalar().ToString();

            SqlConnection conn3 = new SqlConnection(constr);
            conn3.Open();
            string sql3 =string.Format("SELECT SUM(skje) FROM [BHairDB].[dbo].[收入明细] where skfs='现金' and '{0}'<=djrq and '{1}'>=djrq and djh like '%{2}%' ", dtpbegin.Text, dtpend.Text,xx);
            SqlCommand comm3 = new SqlCommand(sql3,conn3);
            lbxj.Text = comm3.ExecuteScalar().ToString();
            SqlConnection conn4 = new SqlConnection(constr);
            conn4.Open();
            string sql4= string.Format("SELECT SUM(skje) FROM [BHairDB].[dbo].[收入明细] where skfs='微信' and '{0}'<=djrq and '{1}'>=djrq and djh like '%{2}%'", dtpbegin.Text, dtpend.Text,xx);
            SqlCommand comm4 = new SqlCommand(sql4,conn4);
            lbwx.Text = comm4.ExecuteScalar().ToString();

            SqlConnection conn5 = new SqlConnection(constr);
            conn5.Open();
            string sql5= string.Format("SELECT SUM(skje) FROM [BHairDB].[dbo].[收入明细] where skfs='支付宝' and '{0}'<=djrq and '{1}'>=djrq and djh like '%{2}%'", dtpbegin.Text, dtpend.Text,xx);
            SqlCommand comm5 = new SqlCommand(sql5,conn5);
            lbzfb.Text= comm5.ExecuteScalar().ToString();

            SqlConnection conn6 = new SqlConnection(constr);
            conn6.Open();
            string sql6= string.Format("SELECT SUM(skje) FROM [BHairDB].[dbo].[收入明细] where skfs='银联卡' and '{0}'<=djrq and '{1}'>=djrq and djh like '%{2}%'", dtpbegin.Text, dtpend.Text,xx);
            SqlCommand comm6 = new SqlCommand(sql6,conn6);
            lbylk.Text= comm6.ExecuteScalar().ToString();
            conn.Close();
            conn1.Close();
            conn2.Close();
            conn3.Close();
            conn4.Close();
            conn5.Close();
            conn6.Close();
            return ds;
        }

        private void frmsrmx_Load(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {
            Xtrasrmx sr = new Xtrasrmx();
            sr.DataSource = dataGridView1.DataSource;
            sr.DataAdapter = dataGridView1.DataSource;
            sr.DataMember = dataGridView1.DataSource.ToString();
            sr.ShowPreview();
        }

        private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
        {
            Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
       e.RowBounds.Location.Y,
       dataGridView1.RowHeadersWidth - 4,
       e.RowBounds.Height);

            TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
            dataGridView1.RowHeadersDefaultCellStyle.Font,
                rectangle,
                dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
                TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
        }
    }
}
